<template>
  <router-view></router-view>
</template>

<script setup>
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

onMounted(() => {
  // 检查是否有token
  const token = localStorage.getItem('token')
  const currentPath = router.currentRoute.value.path
  
  // 如果没有token且不在登录页，重定向到登录页
  if (!token && currentPath !== '/login') {
    router.replace('/login')
  }
  // 如果有token且在根路径，重定向到首页
  else if (token && currentPath === '/') {
    router.replace('/home/dashboard')
  }
})
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  width: 100%;
}

#app {
  height: 100%;
  width: 100%;
}
</style> 